package com.greenantmall.bean;

import java.util.ArrayList;
import java.util.List;

import com.avos.avoscloud.AVACL;
import com.avos.avoscloud.AVClassName;
import com.avos.avoscloud.AVRelation;
import com.avos.avoscloud.AVRole;

/**
 * 大分类：下面包含小分类：goodsstyle
 * @author minfanfu
 * @since 3.8
 */
@AVClassName(AntAVObject.CLASS_TRADESTYLE)
public class TradeStyle extends AntAVObject {
		
	public static final String ATTR_USRID ="usrId";
	public static final String ATTR_NAME ="name";
	public static final String ATTR_FILE ="image";
	public static final String ATTR_SHOWINDEX ="showIndex";
	public static final String ATTR_SHOWSTYLE ="showStyle";
	public static final String ATTR_SECTIONNUM ="sectionNum";
	public static final String ATTR_GOODSSTYLELIST ="goodsStyleList";
	
	private List<GoodsStyles> goodsStylesList;
	
	private AVRole customRole;

	public TradeStyle() {
		super();			
		setAccessCtrl();
	}
	
	public TradeStyle(String str) {
		super(str);
		setAccessCtrl();		
	}
	
	public String getFile()
	{
		return this.getString(ATTR_FILE);
	}
	public void setFile(String name)
	{
		this.put(ATTR_FILE,name);
	}
	
	public String getName()
	{
		return this.getString(ATTR_NAME);
	}
	public void setName(String name)
	{
		this.put(ATTR_NAME,name);
	}
	
	public String getFileUrl()
	{
		try {
			return this.getAVFile(ATTR_FILE).getUrl();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	public void setFileUrl(String url)
	{
	    this.put(ATTR_FILE,url);
	}

	public int getSectionNum()
	{
		return this.getInt(ATTR_SECTIONNUM);
	}
	public void setObjectId(int objectId)
	{
	    this.put(ATTR_SECTIONNUM,objectId);
	}
	
	public TradeStyle getInstance()
	{
		return this;
	}
	public String getUserId() {
		return this.getString(ATTR_USRID);
	}

	private void setUserId(String userId) {
		this.put(ATTR_USRID,userId);
	}
	
	public String getShowStyle() {
		return this.getString(ATTR_SHOWSTYLE);
	}
	
	public void setShowStyle(String showStyle) {
		this.put(ATTR_SHOWSTYLE, showStyle);
	}
	
	public int getShowIndex()
	{
		try {
			return Integer.parseInt(this.getString(ATTR_SHOWINDEX));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return 0;
	}
	public void setShowIndex(int index)
	{
		this.put(ATTR_SHOWINDEX,index);
	}
	
	private int setAccessCtrl() {
		
		acl = new AVACL();
		acl.setPublicReadAccess(true);//�˴����õ��������˵Ŀɶ�Ȩ��
		acl.setPublicWriteAccess(false);
		this.setACL(acl);
//		acl.setReadAccess(AVUser.getCurrentUser(), true);
//		acl.setWriteAccess(AVUser.getCurrentUser(), true);//�������������ļ������ߵ�дȨ��
//		this.setACL(acl);
//		this.setUserId(AVUser.getCurrentUser().getObjectId());
//		AVQuery<AVRole> query = new AVQuery<AVRole>("_Role");
//		query.whereEqualTo("name", "custom");
//		query.findInBackground(new FindCallback<AVRole>() {
//			@Override
//		    public void done(List<AVRole> avObjects, AVException e) {
//		        if (e == null) {
//		            Log.d("�ɹ�", "��ѯ��" + avObjects.size() + " ����������������");
//		            customRole=(AVRole)avObjects.get(0);   
//		            acl.setRoleReadAccess(customRole,true);
//		            getInstance().setACL(acl);
//		            
//		        } else {
//		            Log.d("ʧ��", "��ѯ����: " + e.getMessage());
//		            //acl.setPublicReadAccess(true);//�˴����õ��������˵Ŀɶ�Ȩ��
//		        }
//		    }			
//		
//		});
		return 0;
	}
	
	public AVRelation<GoodsStyles> getGoodsStylesRelation()
    {
        return this.getRelation(ATTR_GOODSSTYLELIST);
    }
    public void removeGoodsStylesRelation(GoodsStyles goods)
    {       
        this.getRelation(ATTR_GOODSSTYLELIST).remove(goods);
    }

    public List<GoodsStyles> getGoodsStylesList()
    {
        if(goodsStylesList==null)
        {
            goodsStylesList=new ArrayList<GoodsStyles>(); 
        }
        return goodsStylesList;
    }

    public void setGoodsStylesList(List<GoodsStyles> goodsStylesList)
    {
        this.goodsStylesList = goodsStylesList;
    }
	
}
